package cn.com.zp.util.base;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SysUtils {
	/**
	 * 调用系统的exe文件
	 * 
	 * @param exeFileName
	 */
	public static void executeExeFile(String exeFileName) {
		Runtime rt = Runtime.getRuntime();
		try {
			rt.exec(exeFileName);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 执行cmd命令
	 * 
	 * @param cmdStr
	 */
	public static void executeCMD(String cmdStr) {
		try {
			Process pr = Runtime.getRuntime().exec(cmdStr);
			BufferedReader br = new BufferedReader(new InputStreamReader(
					pr.getInputStream()));
			String s = null;
			while ((s = br.readLine()) != null) {
				System.out.println(s);
			}
			br.close();
			pr.waitFor();
			if (pr.exitValue() == 0) {
				System.out.println("运行成功！");
			} else {
				System.out.println("# Please check the name and try again.");
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
